﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class System_UserManage : ATPages
{
    ZSql info = new ZSql();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            HidModuId.Value = Request["moduid"].ToString();
            InitDept(null, GetDept());

            TreeViewClass.SetImage(tvDept, "../images/depts.gif", "../images/depts.gif", "../images/dept.gif");

            tvDept.ShowLines = true;
        }
    }

    private void InitDept(TreeNode pnode,DataTable dt)
    {
        string pid = "0";

        if (pnode != null)
        {
            pid = pnode.Value;
        }

        DataRow[] rows = dt.Select("parentid = " + pid);

        if (rows.Length > 0 && pnode != null)
        {
            pnode.SelectAction = TreeNodeSelectAction.None;
        }

        for (int i = 0; i < rows.Length; i++)
        {
            TreeNode node = new TreeNode();
            node.Text = rows[i]["deptname"].ToString();
            node.Value = rows[i]["deptid"].ToString();
            node.NavigateUrl = "User.aspx?deptid=" + node.Value + "&moduid=" + HidModuId.Value;
            node.Target = "info";

            if (pid == "0")
                tvDept.Nodes[0].ChildNodes.Add(node);
            else
                pnode.ChildNodes.Add(node);

		InitDept(node,dt);
        }
    }

    private DataTable GetDept()
    {
        DataTable dt = new DataTable();

        info.Open("select deptid,deptname,parentid from department");

        dt = info.m_table;

        info.Close();

        return dt;
    }
}
